package com.caseprocessing.model;

/**
 * 文本块模型
 * 表示页面中的一个文本区域
 */
public class TextBlock {
    
    private String blockId;
    private BoundingBox bbox;
    private String text;
    private double confidence;
    private String fontType;
    private int fontSize;
    
    public TextBlock() {}
    
    public TextBlock(String blockId, String text, double confidence) {
        this.blockId = blockId;
        this.text = text;
        this.confidence = confidence;
    }
    
    // Getters and Setters
    public String getBlockId() { return blockId; }
    public void setBlockId(String blockId) { this.blockId = blockId; }
    
    public BoundingBox getBbox() { return bbox; }
    public void setBbox(BoundingBox bbox) { this.bbox = bbox; }
    
    public String getText() { return text; }
    public void setText(String text) { this.text = text; }
    
    public double getConfidence() { return confidence; }
    public void setConfidence(double confidence) { this.confidence = confidence; }
    
    public String getFontType() { return fontType; }
    public void setFontType(String fontType) { this.fontType = fontType; }
    
    public int getFontSize() { return fontSize; }
    public void setFontSize(int fontSize) { this.fontSize = fontSize; }
    
    /**
     * 判断是否为标题类型文本
     */
    public boolean isTitle() {
        return "title".equals(fontType) || fontSize > 14;
    }
    
    /**
     * 判断文本是否可能包含日期
     */
    public boolean containsDate() {
        if (text == null) return false;
        // 检查8位数字日期格式 YYYYMMDD
        return text.matches(".*\\d{8}.*") || 
               text.matches(".*\\d{4}年\\d{1,2}月\\d{1,2}日.*");
    }
    
    /**
     * 判断文本是否可能是文号
     */
    public boolean isDocumentNumber() {
        if (text == null) return false;
        // 检查文号格式，如：xx执法〔2024〕001号
        return text.matches(".*[〔\\[]\\d{4}[〕\\]]\\d+号.*") ||
               text.matches(".*\\d{4}.*第\\d+号.*");
    }
}